package com.liaoct.lct.listener;

import java.util.List;

import com.liaoct.lct.activity.BaseActivity;
import com.liaoct.lct.activity.R;
import com.liaoct.lct.runnable.DelayCloseGuideRunnable;

import android.os.Handler;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.widget.ImageView;

/**
 * ViewPager翻页监听类
 * 
 * @version 2013/07/11
 * @author liaoct
 * 
 */
public class ViewPagerOnPageChangListener implements OnPageChangeListener {

	private List<ImageView> list;

	private BaseActivity activity;

	private Thread tr;

	private DelayCloseGuideRunnable runnable;

	public ViewPagerOnPageChangListener(BaseActivity activity,
			List<ImageView> list) {
		this.list = list;
		this.activity = activity;
		runnable = new DelayCloseGuideRunnable(this.activity);
		tr = new Thread(runnable);
	}

	@Override
	public void onPageScrollStateChanged(int index) {

	}

	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {

	}

	@Override
	public void onPageSelected(int index) {
		if (null != list) {
			redraw(index);
			if (list.size() - 1 == index) {
				tr.start();
			}
		}
	}

	/**
	 * 小圆点重绘
	 * 
	 * @param index
	 */
	public void redraw(int index) {
		for (int i = 0; i < list.size(); i++) {
			ImageView view = list.get(i);
			if (i == index) {
				view.setBackgroundResource(R.drawable.select);
				continue;
			}
			view.setBackgroundResource(R.drawable.unselect);
		}
	}

}
